"use strict";
/* Controllers */
app.controller("yarnApplicationDetailController", ['$scope', '$location', '$rootScope', '$routeParams', 'yarnApplicationDetailService', function ($scope, $location, $rootScope, $routeParams, yarnApplicationDetailService) {

    var vm = $scope.vm = {};
    vm.p = {};
    vm.p.id = $routeParams.id; // 如果ID!=0为更新

    var errorFn = function (result) {
        alert(result);
    };
    $scope.getYarnApplication = function() {
        var vm = $scope.vm;
        var params = {id: vm.p.id};
        var procFn = function (response) {
            if (response.success && response.data) {
                vm.p = response.data;
            } else {
                alert(response.message);
            }
        };
        yarnApplicationDetailService.getYarnApplication(params, procFn, errorFn);
    };

    $scope.killYarnApplication = function () {
        var vm = $scope.vm;

        var params = {
            id: vm.p.id,
            appID: vm.p.appID,
            queue: vm.p.queue,
            clusterName: vm.p.clusterName,
            accessID: vm.p.accessID
        };
        var procFn = function (response) {
            if (response.success && response.data) {
                window.location = "#/star/order/yarn_application_list/off/0";
                alert("执行成功！")
            } else {
                alert(response.message);
            }
        };
        yarnApplicationDetailService.killYarnApplication(params, procFn, errorFn);
    };

    $scope.getYarnApplication();
}]);


/* Services */
app.service('yarnApplicationDetailService', ['ajaxService', function (ajaxService) {
    this.getYarnApplication = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/yarn_application/getYarnApplication.do", successFunction, errorFunction);
    };

    this.killYarnApplication = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/yarn_application/killYarnApplication.do", successFunction, errorFunction);
    };
}]);

